using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace SolutionClone.Model
{
    public class ConverterFactory
    {
        private Dictionary<string, Type> factoryData = new Dictionary<string, Type>();
        public ConverterFactory()
        {
            factoryData.Add(".log4net", typeof(DefaultConverter));
            factoryData.Add(".btdfproj", typeof(DefaultConverter));
            factoryData.Add(".xml", typeof(DefaultConverter));
            factoryData.Add(".btproj", typeof(DefaultConverter));
            factoryData.Add(".nant", typeof(DefaultConverter));
            factoryData.Add(".build", typeof(DefaultConverter));
            factoryData.Add(".csproj", typeof(DefaultConverter));
            factoryData.Add(".vbproj", typeof(DefaultConverter));
        }
        public IConverter GetConverter(string filePath, string oldName, string newName)
        {
            IConverter converter = null;
            var extension = Path.GetExtension(filePath).ToLower();

            if (factoryData.Keys.Contains(extension))
            {
                converter = Activator.CreateInstance(factoryData[extension]) as IConverter;
                converter.FilePath = filePath;
                converter.OldName = oldName;
                converter.NewName = newName;
            }

            return converter;
        }
    }
}
